import shutil
import tkinter as tk
import tkinter.ttk
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from tkinter.messagebox import *
import xlwings as xw
import os
import os.path
import glob
import time
import fnmatch
import sys
from openpyxl.utils import get_column_letter
import re
import subprocess
import shutil


startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

# 调整为SW_HIDE,表示创建的进程窗口在显示时不会激活
startupinfo.wShowWindow = subprocess.SW_HIDE

# 取得路径
def app_path():
    if hasattr(sys, 'frozen'):  # 可执行文件走这里
        return os.path.abspath(sys.executable)
    return os.path.abspath(__file__)  # 源码走这里

# 界面作成
window = tk.Tk()
window.title("Check jira")
window.geometry("750x250+600+400") 

# 创建 PanedWindow
paned_window = ttk.PanedWindow(window, orient=tk.HORIZONTAL)
paned_window.pack(fill=tk.BOTH, expand=True)
# 创建左侧的 Frame 用于放置按钮
left_frame = ttk.Frame(paned_window, width=150)
paned_window.add(left_frame, weight=1)
# 创建右侧的 Frame 用于显示具体内容
right_frame = ttk.Frame(paned_window)
paned_window.add(right_frame, weight=5)
# -------------------------------------------------------------------------------------page_1-------------------------------------------------------------------------------------
# 界面参数
page_1 = ttk.Frame(right_frame)

# 文件路径
def importfile_file_select_1():
    file_path = filedialog.askopenfilename()
    import_1.config(text=file_path)
import_1 = tk.Message(page_1, width=300, text="")
import_1.place(x=20, y=70, anchor="w")
import_botton_1 = tk.Button(page_1, text="specchange file", width=15, command=importfile_file_select_1)
import_botton_1.place(x=350, y=50)

def schedule_file_select_1():
    file_path = filedialog.askopenfilename()
    schedule_1.config(text=file_path)
schedule_1 = tk.Message(page_1, width=300, text="")
schedule_1.place(x=20, y=115, anchor="w")
schedule_botton_1 = tk.Button(page_1, text="schedule file", width=15, command=schedule_file_select_1)
schedule_botton_1.place(x=350, y=100)

def start_1():
    datacheck_1(import_1["text"], schedule_1["text"])

start_botton_1 = tk.Button(page_1, text="开始", width=15, command=start_1)
start_botton_1.place(x=350, y=150)

def datacheck_1(specchange_file, schedule_file):
    try:
        os.remove(str(os.path.dirname(app_path())) + "\\" + "error.txt")
    except Exception as e:
        pass

    app = xw.App(visible=False,add_book=False)

    error_list = []
    specchange_dict = {}
    hmi_dict = {}
    try:
        specchange_book = app.books.open(specchange_file, update_links=False)
        sheet = specchange_book.sheets(1)
        cell_keyword = sheet.range("1:1").api.Find("Custom field (Epic Link)")
        if cell_keyword:
            Epic_col = cell_keyword.Column - 1
            max_row = sheet.range(f"{get_column_letter(cell_keyword.Column)}{str(sheet.cells.last_cell.row)}").end('up').row
            max_col = sheet.range((1, sheet.cells.last_cell.column)).end('left').column
            cell_keyword = sheet.range("1:1").api.Find("Custom field (HMI Story Link)")
            HMI_col = cell_keyword.Column - 1
            # 获取所有数据
            tmp_data = sheet.range((1,1), (max_row, max_col)).value
            # 打印数据
            row_num = 1
            for row in tmp_data:
                if row_num != 1:
                    row_key = str(row[Epic_col]).strip()
                    row_val = str(row[HMI_col]).strip().split('/')[-1]
                    if row_key != "None" and row_val != "None":
                        row_value = {}
                        if row_key in specchange_dict:
                            if row_val not in specchange_dict[row_key]["row_val"]:
                                specchange_dict[row_key]["row_val"] = f"{specchange_dict[row_key]["row_val"]},{row_val}"
                            specchange_dict[row_key]["row_num"] = f"{specchange_dict[row_key]["row_num"]},{row_num}"
                        else:
                            row_value["row_val"] = row_val
                            row_value["row_num"] = row_num
                            specchange_dict[row_key] = row_value
                        row_value = {}
                        if row_val in hmi_dict:
                            if row_key not in hmi_dict[row_val]["row_val"]:
                                hmi_dict[row_val]["row_val"] = f"{hmi_dict[row_val]["row_val"]},{row_key}"
                            hmi_dict[row_val]["row_num"] = f"{hmi_dict[row_val]["row_num"]},{row_num}"
                        else:
                            row_value["row_val"] = row_key
                            row_value["row_num"] = row_num
                            hmi_dict[row_val] = row_value
                    else:
                        if row_key != "None" or row_val != "None":
                            error_list.append(f"[{specchange_file}]文件, 第[{row_num}]行[Custom field (Epic Link)]列/[Custom field (HMI Story Link)]列数据为[None]")
                row_num += 1
        else:
            app.quit()
            print(showwarning(title="warning", message=f"[{specchange_file}]文件[sheet1]第一行没有找到[Custom field (Epic Link)]列"))
            return
        specchange_book.close()
    except Exception as e:
        app.quit()
        print(showwarning(title="warning", message=f"读取[{specchange_file}]文件失败[{e}]"))
        return

    for key,value in specchange_dict.items():
        if "," in value["row_val"]:
            error_list.append(f"[{specchange_file}]文件, [Epic Link:{key}]对应的[HMI Story Link]检查到多条数据,数据内容[{value["row_val"]}]对应行数[{value["row_num"]}]")
    for key,value in hmi_dict.items():
        if "," in value["row_val"]:
            error_list.append(f"[{specchange_file}]文件, [HMI Story Link:{key}]对应的[Epic Link]检查到多条数据,数据内容[{value["row_val"]}]对应行数[{value["row_num"]}]")

    schedule_dict = {}
    hmi_ticket = {}
    try:
        schedule_book = app.books.open(schedule_file, update_links=False)
        for sheet in schedule_book.sheets:
            if f"ScheduleTable_" in sheet.name:
                cell_keyword = schedule_book.sheets(sheet.name).range("5:5").api.Find("Epic ticket")
                max_row = sheet.range(f"{get_column_letter(cell_keyword.Column)}{str(sheet.cells.last_cell.row)}").end('up').row
                max_col = sheet.range((5, sheet.cells.last_cell.column)).end('left').column
                if cell_keyword:
                    Epic_col = cell_keyword.Column - 1
                    cell_keyword = schedule_book.sheets(sheet.name).range("5:5").api.Find("HMI Story ticket")
                    HMI_col = cell_keyword.Column - 1
                    # 获取所有数据
                    tmp_data = sheet.range((1,1), (max_row, max_col)).value
                    # 打印数据
                    row_num = 1
                    for row in tmp_data:
                        if row_num > 5:
                            row_key = str(row[Epic_col]).strip()
                            row_val = str(row[HMI_col]).strip()
                            if row_key != "None" and row_val != "None" and row_key != "-" and row_val != "-":
                                if "\n" in row_key:
                                    row_key = row_key.replace("\r","")
                                    row_val = row_val.replace("\r","")
                                    key_list = row_key.split("\n")
                                    val_list = row_val.split("\n")
                                    for index, item in enumerate(key_list):
                                        row_key = str(item).strip()
                                        row_val = str(val_list[index]).strip()
                                        row_value = {}
                                        if row_key in schedule_dict:
                                            if row_val not in schedule_dict[row_key]["row_val"]:
                                                schedule_dict[row_key]["row_val"] = f"{schedule_dict[row_key]["row_val"]},{row_val}"
                                            if sheet.name not in schedule_dict[row_key]["row_num"]:
                                                schedule_dict[row_key]["row_num"] = f"{schedule_dict[row_key]["row_num"]},{sheet.name}:{row_num}"
                                            else:
                                                schedule_dict[row_key]["row_num"] = f"{schedule_dict[row_key]["row_num"]},{row_num}"
                                        else:
                                            row_value["row_val"] = row_val
                                            row_value["row_num"] = f"{sheet.name}:{row_num}"
                                            schedule_dict[row_key] = row_value
                                        row_value = {}
                                        if row_key in hmi_ticket:
                                            if hmi_ticket[row_val]["row_val"] != row_key:
                                                if row_val not in hmi_ticket[row_val]["row_val"]:
                                                    hmi_ticket[row_val]["row_val"] = f"{hmi_ticket[row_val]["row_val"]},{row_key}"
                                                if sheet.name not in hmi_ticket[row_val]["row_num"]:
                                                    hmi_ticket[row_val]["row_num"] = f"{hmi_ticket[row_val]["row_num"]},{sheet.name}:{row_num}"
                                                else:
                                                    hmi_ticket[row_val]["row_num"] = f"{hmi_ticket[row_val]["row_num"]},{row_num}"
                                        else:
                                            row_value["row_val"] = row_key
                                            row_value["row_num"] = f"{sheet.name}:{row_num}"
                                            hmi_ticket[row_val] = row_value
                                else:
                                    row_value = {}
                                    if row_key in schedule_dict:
                                        if row_val not in schedule_dict[row_key]["row_val"]:
                                            schedule_dict[row_key]["row_val"] = f"{schedule_dict[row_key]["row_val"]},{row_val}"
                                        if sheet.name not in schedule_dict[row_key]["row_num"]:
                                            schedule_dict[row_key]["row_num"] = f"{schedule_dict[row_key]["row_num"]},{sheet.name}:{row_num}"
                                        else:
                                            schedule_dict[row_key]["row_num"] = f"{schedule_dict[row_key]["row_num"]},{row_num}"
                                    else:
                                        row_value["row_val"] = row_val
                                        row_value["row_num"] = f"{sheet.name}:{row_num}"
                                        schedule_dict[row_key] = row_value
                                    row_value = {}
                                    if row_key in hmi_ticket:
                                        if hmi_ticket[row_val]["row_val"] != row_key:
                                            if row_val not in hmi_ticket[row_val]["row_val"]:
                                                hmi_ticket[row_val]["row_val"] = f"{hmi_ticket[row_val]["row_val"]},{row_key}"
                                            if sheet.name not in hmi_ticket[row_val]["row_num"]:
                                                hmi_ticket[row_val]["row_num"] = f"{hmi_ticket[row_val]["row_num"]},{sheet.name}:{row_num}"
                                            else:
                                                hmi_ticket[row_val]["row_num"] = f"{hmi_ticket[row_val]["row_num"]},{row_num}"
                                    else:
                                        row_value["row_val"] = row_key
                                        row_value["row_num"] = f"{sheet.name}:{row_num}"
                                        hmi_ticket[row_val] = row_value
                            else:
                                error_list.append(f"[{schedule_file}]文件, [sheet:{sheet.name}]第[{row_num}]行[Epic ticket]列/[HMI Story ticket]列数据为[None/-]")
                        row_num += 1
                else:
                    app.quit()
                    print(showwarning(title="warning", message=f"[{schedule_file}]文件[sheet:{sheet.name}]中第五行没有找到[Epic ticket]列"))
                    return
        schedule_book.close()
    except Exception as e:
        app.quit()
        print(showwarning(title="warning", message=f"读取[{schedule_file}]文件失败[{e}]"))
        return

    for key,value in schedule_dict.items():
        if "," in value["row_val"]:
            error_list.append(f"[{schedule_file}]文件, [Epic ticket:{key}]对应的[HMI Story ticket]检查到多条数据,数据内容[{value["row_val"]}]对应行数[{value["row_num"]}]")
    for key,value in hmi_ticket.items():
        if "," in value["row_val"]:
            error_list.append(f"[{schedule_file}]文件, [HMI Story ticket:{key}]对应的[Epic ticket]检查到多条数据,数据内容[{value["row_val"]}]对应行数[{value["row_num"]}]")

    try:
        for key,values in specchange_dict.items():
            if key in schedule_dict:
                if schedule_dict[key]["row_val"] != values["row_val"]:
                    if "," in values["row_val"]:
                        for val in str(values["row_val"]).split(","):
                            if val not in schedule_dict[key]["row_val"]:
                                error_list.append(f"[{specchange_file}]文件中[Epic:{key}]有多条[HMI]匹配数据, 其中[HMI:{val}] 与 [{schedule_file}]文件中[HMI:{schedule_dict[key]["row_val"]}] 不匹配")
                    else:
                        error_list.append(f"[{specchange_file}]文件中第[{values["row_num"]}]行数据[Epic:{key}][HMI:{values["row_val"]}] 与 [{schedule_file}]文件中第[{schedule_dict[key]["row_num"]}]行数据[Epic:{key}][HMI:{schedule_dict[key]["row_val"]}] 不匹配")
            else:
                error_list.append(f"[{specchange_file}]文件第[{values["row_num"]}]行数据[Epic:{key}], 在[{schedule_file}]文件中没有找到匹配数据 !!!")
    except Exception as e:
        app.quit()
        print(showwarning(title="warning", message=f"[{specchange_file}]文件与[{schedule_file}]文件数据对照检查失败[{e}]"))
        return
    
    with open(str(os.path.dirname(app_path())) + "\\error.txt", 'a', encoding='utf-8') as f:
        for error in error_list:
            f.write(str(error) + '\n')
    app.quit()
    print(showinfo(title="info", message=f"specchange表与schedule表检查[SUCCESS END] !!!"))

def time_change(time_before):
    time_after = time_before.replace(chr(0), "")
    time_after = time_after.replace("-", "/")
    time_after = time_after.replace("/0", "/")
    time_after = time_after.replace("00:00:00", "")
    time_after = time_after.replace(" ", "")
    return time_after

# -------------------------------------------------------------------------------------page_2-------------------------------------------------------------------------------------
# 界面参数
page_2 = ttk.Frame(right_frame)
# notebook.add(page_2, text="")

# 文件路径
def story_file_select_2():
    file_path = filedialog.askopenfilename()
    story_2.config(text=file_path)
story_2 = tk.Message(page_2, width=300, text="")
story_2.place(x=20, y=50, anchor="w")
story_botton_2 = tk.Button(page_2, text="story file", width=10, command=story_file_select_2)
story_botton_2.place(x=350, y=30)

def C3IM_file_select_2():
    file_path = filedialog.askopenfilename()
    C3IM_2.config(text=file_path)
C3IM_2 = tk.Message(page_2, width=300, text="")
C3IM_2.place(x=20, y=100, anchor="w")
C3IM_botton_1 = tk.Button(page_2, text="C3IM file", width=10, command=C3IM_file_select_2)
C3IM_botton_1.place(x=350, y=80)

def schedule_file_select_2():
    file_path = filedialog.askopenfilename()
    schedule_2.config(text=file_path)
schedule_2 = tk.Message(page_2, width=300, text="")
schedule_2.place(x=20, y=145, anchor="w")
schedule_botton_1 = tk.Button(page_2, text="schedule file", width=10, command=schedule_file_select_2)
schedule_botton_1.place(x=350, y=130)


def start_2():
    datacheck_2(story_2["text"], C3IM_2["text"], schedule_2["text"])

start_botton_2 = tk.Button(page_2, text="开始", width=10, command=start_2)
start_botton_2.place(x=350, y=180)

def datacheck_2(story_file, C3IM_file, schedule_file):
    try:
        os.remove(str(os.path.dirname(app_path())) + "\\" + "error.txt")
    except:
        pass

    app = xw.App(visible=False,add_book=False)
    try:
        story_book = app.books.open(story_file, update_links=False)
        if story_book.sheets(1).range("A1").value == "Issue key":
            story_data = story_book.sheets(1).range('A:A').value
            story_list = [item for item in story_data if item != "Issue key" and item is not None]
        else:
            app.quit()
            print(showwarning(title="warning", message=f"[{story_file}]文件的[A1]单元格不是[Issue key]请选择正确的story file !!!"))
            return
        story_book.close()
    except Exception as e:
        app.quit()
        print(showwarning(title="warning", message=f"读取[{story_file}]文件失败[{e}]"))
        return

    error_list = []
    sp_col_list = []
    C3IM_dict = {}
    try:
        C3IM_book = app.books.open(C3IM_file, update_links=False)
        sheet = C3IM_book.sheets(1)
        cell_keyword = sheet.range("1:1").api.Find("Summary")
        if cell_keyword:
            find_col = cell_keyword.Column - 1
            max_row = sheet.range(f"{get_column_letter(cell_keyword.Column)}{str(sheet.cells.last_cell.row)}").end('up').row
            max_col = sheet.range((1, sheet.cells.last_cell.column)).end('left').column
            # 获取所有数据
            tmp_data = sheet.range((1,1), (max_row, max_col)).value
            # 打印数据
            row_num = 1
            for row in tmp_data:
                if row_num != 1:
                    row_key = ""
                    summary = str(row[find_col]).strip()
                    if "[SWE.1]" in summary and "[SWE.1] [PI26][SP4] Create RTM doc" not in summary:
                        row_key = "[SWE1 - SRS]"
                    # elif "[SWE.2]" in summary:
                    #     row_key = "[SWE2 - SAD]"
                    # elif "[SWE.3]" in summary:
                    #     row_key = "[SWE3a - SDD, GMD]"
                    elif "[SWE.4]" in summary:
                        if "Unit Test Report" in summary:
                            row_key = "[SWE4 - UTR]"
                        elif "GUI Test Report" in summary:
                            row_key = "[SWE4 - GTR]"
                        elif "Scenario Test Report" in summary:
                            row_key = "[SWE4 - STR]"
                        elif "SAR Static code analysis" in summary:
                            row_key = "[SWE4 - SAR]"
                        else:
                            error_list.append(f"文件[{C3IM_file}]第[{row_num}]行[Summary]列数据[[SWE.4]没有找到对应的翻译信息")
                    # elif "[SWE.5]" in summary:
                    #     row_key = "[SWE5 - PIT]"
                    else:
                        error_list.append(f"文件[{C3IM_file}]第[{row_num}]行[Summary]列数据[{summary}]按规则不做检查!")
                        row_num += 1
                        continue

                for index, item in enumerate(row):
                    tmp_key = str(tmp_data[0][index]).strip()
                    item = str(item).strip()
                    if row_num == 1:
                        if tmp_key == "Sprint":
                            sp_col_list.append(index)
                    else:
                        if tmp_key == "Outward issue link (Blockers)" or tmp_key == "Outward issue link (Blocks)":
                            if item != "None" and item in story_list:
                                for sp_col in sp_col_list:
                                    sp_tmp = str(row[sp_col]).strip()
                                    if sp_tmp != "None":
                                        sp_val = ""
                                        pattern = r'^PI\d+\.(\d)(?:\([\w\s]+\))?$'
                                        matches = re.match(pattern, sp_tmp)
                                        if matches:
                                            row_value_key = f"{row_key}-[SP{str(matches.group(1)).strip()}]"
                                            row_value = {}
                                            row_value[row_value_key] = str(row_num)
                                            if item in C3IM_dict:
                                                if row_value_key in C3IM_dict[item]:
                                                    C3IM_dict[item][row_value_key] = f"{C3IM_dict[item][row_value_key]},{str(row_num)}"
                                                else:
                                                    C3IM_dict[item][row_value_key] = str(row_num)
                                            else:
                                                C3IM_dict[item] = row_value
                                        else:
                                            error_list.append(f"文件[{C3IM_file}]第[{row_num}]行, Sprint 列数据[{sp_tmp}]格式不正确")
                                            continue
                row_num += 1
            # print(C3IM_dict)
        else:
            app.quit()
            print(showwarning(title="warning", message=f"[{C3IM_file}]文件sheet1中第一行未找到[Summary]列"))
            return
        C3IM_book.close()
    except Exception as e:
        app.quit()
        print(showwarning(title="warning", message=f"读取[{C3IM_file}]文件失败[{e}]"))
        return
        
    schedule_dict = {}
    try:
        schedule_book = app.books.open(schedule_file, update_links=False)
        for sheet in schedule_book.sheets:
            if f"ScheduleTable_" in sheet.name:
                cell_keyword = sheet.range("5:5").api.Find("HMI Story ticket")
                if cell_keyword:
                    find_col = cell_keyword.Column - 1
                    max_row = sheet.range(f"{get_column_letter(cell_keyword.Column)}{str(sheet.cells.last_cell.row)}").end('up').row
                    max_col = sheet.range((5, sheet.cells.last_cell.column)).end('left').column
                    cell_keyword = sheet.range("5:5").api.Find("Release Plan\n(=Implementation done plan)")
                    sp_col = cell_keyword.Column - 1
                    # 获取所有数据
                    tmp_data = sheet.range((1,1), (max_row, max_col)).value
                    # 打印数据
                    swe_col_list = []
                    row_num = 1
                    for row in tmp_data:
                        if row_num == 5:
                            for index, item in enumerate(row):
                                item = str(item).strip()
                                if item == "First":
                                    if str(tmp_data[row_num-2][index]).strip() == "Plan":
                                        item_2 = str(tmp_data[row_num-3][index]).strip()
                                        if item_2 == "SWE1 - SRS":
                                            swe_col_list.append(index)
                                        # if item_2 == "SWE2 - SAD":
                                        #     swe_col_list.append(index)
                                        # if item_2 == "SWE3a - SDD, GMD":
                                            # swe_col_list.append(index)
                                        if item_2 == "SWE3b - MR":
                                            swe_col_list.append(index)
                                        if item_2 == "SWE4 - STR":
                                            swe_col_list.append(index)
                                        if item_2 == "SWE4 - GTR":
                                            swe_col_list.append(index)
                                        if item_2 == "SWE4 - UTR":
                                            swe_col_list.append(index)
                                        if item_2 == "SWE4 - SAR":
                                            swe_col_list.append(index)
                                        # if item_2 == "SWE5 - PIT":
                                        #     swe_col_list.append(index)
                                if item == "Delivery to Marelli":
                                    if len(swe_col_list) != 6:
                                        app.quit()
                                        print(showwarning(title="warning", message=f"[{schedule_file}]文件sheet1中第3-5行title格式不正确"))
                                        return
                                    break
                        if row_num > 5:
                            hmi_val = str(row[find_col]).strip()
                            if hmi_val != "None" and hmi_val != "-" and hmi_val in story_list:
                                row_value = {}
                                row_val = ""
                                sp_val = str(row[sp_col]).strip()
                                pattern = r'^IRI\d+\.0(\d)\.\d+$'
                                matches = re.match(pattern, sp_val)
                                if matches:
                                    sp_val = f"SP{str(matches.group(1)).strip()}"
                                    # print(f"sp_val={sp_val}")
                                for swe_col in swe_col_list:
                                    if str(row[swe_col]).strip() != "NA":
                                        row_value[f"[{tmp_data[2][swe_col]}]-[{sp_val}]"] = f"{sheet.name}:{str(row_num)}"

                                if "\n" in hmi_val:
                                    hmi_val = hmi_val.replace("\r","")
                                    hmi_list = hmi_val.strip("\n")
                                    for hmi in hmi_list:
                                        if hmi in schedule_dict:
                                            for key,value in row_value.items():
                                                if key in schedule_dict[hmi]:
                                                    if sheet.name in schedule_dict[hmi][key]:
                                                        schedule_dict[hmi][key] = f"{schedule_dict[hmi][key]},{str(row_num)}"
                                                    else:
                                                        schedule_dict[hmi][key] = f"{schedule_dict[hmi][key]},{value}"
                                                else:
                                                    schedule_dict[hmi][key] = value
                                        else:
                                            schedule_dict[hmi] = row_value
                                else:
                                    if hmi_val in schedule_dict:
                                        for key,value in row_value.items():
                                            if key in schedule_dict[hmi_val]:
                                                if sheet.name in schedule_dict[hmi_val][key]:
                                                    schedule_dict[hmi_val][key] = f"{schedule_dict[hmi_val][key]},{str(row_num)}"
                                                else:
                                                    schedule_dict[hmi_val][key] = f"{schedule_dict[hmi_val][key]},{value}"
                                            else:
                                                schedule_dict[hmi_val][key] = value
                                    else:
                                        schedule_dict[hmi_val] = row_value
                        row_num += 1
                    # print(schedule_dict)
                else:
                    app.quit()
                    print(showwarning(title="warning", message=f"[{schedule_file}]文件[{sheet.name}]中第五行没有找到[HMI Story ticket]列"))
                    return
        schedule_book.close()
    except Exception as e:
        app.quit()
        print(showwarning(title="warning", message=f"读取[{schedule_file}]文件失败[{e}]"))
        return

    # 遍历列表
    for story in story_list:
        if C3IM_dict.get(story) == None:
            error_list.append(f"[{story}]未在文件[{C3IM_file}]中找到对应有效数据")
            continue
        if schedule_dict.get(story) == None:
            error_list.append(f"[{story}]未在文件[{schedule_file}]中找到对应有效数据")
            continue
        for key,value in C3IM_dict[story].items():
            if key not in schedule_dict[story]:
                error_list.append(f"[{story}]在文件[{C3IM_file}]中第[{value}]行找到数据[{key}], 在文件[{schedule_file}]中未找到对应有效数据")
        for key,value in schedule_dict[story].items():
            if key not in C3IM_dict[story]:
                error_list.append(f"[{story}]在文件[{schedule_file}]中第[{value}]行找到数据[{key}], 在文件[{C3IM_file}]中未找到对应有效数据")
        
    with open(str(os.path.dirname(app_path())) + "\\error.txt", 'a', encoding='utf-8') as f:
        for error in error_list:
            f.write(str(error) + '\n')

    app.quit()
    print(showinfo(title="info", message=f"story票号表、schedule表、C3IM表检查[SUCCESS END] !!!"))

# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# 添加一些内容到页面
ttk.Label(page_1, text="specchange表与schedule表检查").pack(pady=5)
ttk.Label(page_2, text="story票号表、schedule表、C3IM表检查").pack(pady=5)
# 在左侧 Frame 中添加按钮,用于切换页面
def show_page(page):
    for p in [page_1, page_2]:
        p.pack_forget()  # 隐藏所有页面
    page.pack(fill=tk.BOTH, expand=True)  # 显示当前页面

button_1 = ttk.Button(left_frame, text="specchange表与schedule表检查", command=lambda: show_page(page_1))
button_1.pack(pady=10, fill=tk.X)
button_2 = ttk.Button(left_frame, text="story票号表、schedule表、C3IM表检查", command=lambda: show_page(page_2))
button_2.pack(pady=10, fill=tk.X)

# 默认显示第一个页面
show_page(page_1)
# # 将Notebook放入根窗口
# notebook.pack(expand=1, fill="both")

# 回调函数
def refresh():
    window.after(100, refresh)

# 注册第一次回调函数
window.after(100, refresh)

window.mainloop()